# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Contributor: Michał Polański <michal@polanski.me>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=radicale
pkgver=3.0.3
pkgrel=0
pkgdesc="Free and open-source CalDAV and CardDAV server"
url="https://radicale.org/3.0.html"
arch="noarch"
license="GPL-3.0-or-later"
depends="python3 py3-passlib py3-vobject py3-defusedxml py3-dateutil py3-setuptools"
checkdepends="py3-pytest py3-pytest-flake8 py3-pytest-isort py3-pytest-cov py3-waitress"
pkgusers="radicale"
pkggroups="radicale"
install="$pkgname.pre-install"
source="$pkgname-$pkgver.tar.gz::https://github.com/Kozea/Radicale/archive/$pkgver.tar.gz
	$pkgname.initd
	$pkgname.confd"
subpackages="$pkgname-openrc"
builddir="$srcdir/Radicale-$pkgver"

build() {
	python3 setup.py build
}

check() {
	# install the package to test_install directory for testing
	python3 setup.py install --root="$PWD"/test_install

	PYTHONPATH="$PWD"/test_install/usr/lib/python3.8/site-packages \
		pytest
}

package() {
	python3 setup.py install --skip-build --prefix=/usr --root="$pkgdir"

	install -d -o radicale -g radicale "$pkgdir"/var/lib/radicale \
		"$pkgdir"/var/log/radicale

	install -d "$pkgdir"/etc/radicale
	install -m640 -g radicale config "$pkgdir"/etc/radicale/
	install -m640 -g radicale rights "$pkgdir"/etc/radicale/

	install -Dm755 "$srcdir"/radicale.initd "$pkgdir"/etc/init.d/radicale
	install -Dm644 "$srcdir"/radicale.confd "$pkgdir"/etc/conf.d/radicale
}

sha512sums="70a75b7796983bfb0560acb6c673bcd7ff28dd1c0fffa3e97c0ae781b6d03329cb4b614231b86109073a172890d2eb86de48b23e235dfabd66583a007412e70d  radicale-3.0.3.tar.gz
f1eb4477ca7d7d8040837b712289f18d6b62c7f862a8e9bea32968a49b8bf4394360b5440c815aa23df48ba0aaac61bcb8c9d6e7575c3b23da2ac05a45eac194  radicale.initd
09bb6228ba07039b97b317d4547a33b7ebf9c8f47ff72b870fc2f5e46de620e0614d993c5c96d73f0ad6196d469bb0f7206478781abf314af1d598e3132d678e  radicale.confd"
